package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Region;
import cn.wolfcode.luowowo.article.mapper.RegionMapper;
import cn.wolfcode.luowowo.article.service.IRegionService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {

    @Autowired
    private RegionMapper regionMapper;
    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Region> list = regionMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public AjaxResult saveOrUpdate(Region entity) {
        AjaxResult result = new AjaxResult();
        try {
            if (entity.getId() == null){//新增
                regionMapper.insert(entity);

            }else {//更新
                regionMapper.updateByPrimaryKey(entity);
            }
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败");
        }
        return result;
    }

    @Override
    public List<Region> listHotRegions() {
        return regionMapper.listHotRegions();
    }
}
